<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>部门管理</title>
    <#include "../common/link.ftl"/>
    <script>
        $(function () {
            //回显数据
            $(".btn-input").click(function () {
                var json = $(this).data("json");
                console.log(json);
                if (json) {
                    $("input[name='id']").val(json.id);
                    $("input[name='name']").val(json.name);
                    $("input[name='sn']").val(json.sn);
                } else {
                    $("input").val("");
                }
                $('#myModal').modal('show');
            })

            //提交表单
            $(".btn-primary").click(function () {
                $.messager.confirm("温馨提示", "确认保存吗", function () {
                    $("#editForm").ajaxSubmit(function (data) {
                        if (data.success){
                            $.messager.popup("保存成功,两秒后跳转页面")
                            setTimeout(function () {
                                window.location.reload();
                            },2000)
                        }else{
                            $.messager.popup(data.msg);
                        }
                    })
                })
            })
            //删除操作
            $(".btn-delete").click(function () {
                var url = $(this).data("url");
                $.messager.confirm("温馨提示","确定要删除吗",function () {
                    $.get(url,function (data) {
                        if(data.success){
                            $.messager.popup("删除成功,2秒后跳转页面");
                            setTimeout(function () {
                                window.location.reload();
                            },2000)
                        }else{
                            $.messager.popup(data.msg);
                        }
                    })
                })
            })

        })
    </script>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<#include "../common/navbar.ftl" />
    <!--菜单回显-->
<#assign currentMenu="department"/>
<#include "../common/menu.ftl" />
    <div class="content-wrapper">
        <section class="content-header">
            <h1>部门管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/dept/list" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">

                    <a href="javaScript:;" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>

                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered" align="center">
                        <tr>
                            <th>编号</th>
                            <th>部门名称</th>
                            <th>部门编号</th>
                            <th>操作</th>
                        </tr>


                        <#list pageInfo.list as dept>
                            <tr>
                                <td>${dept_index+1}</td>
                                <td>${dept.name}</td>
                                <td>${dept.sn}</td>
                                <td>
                                    <a href="javaScript:;" data-json='${dept.json}'
                                       class="btn btn-info btn-xs btn-input">
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a href="#" data-url="/dept/delete?deptId=${dept.id}"
                                       class="btn btn-danger btn-xs btn-delete">
                                        <span class="glyphicon glyphicon-trash"></span> 删除
                                    </a>
                                </td>
                            </tr>
                        </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl"/>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl" />
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">部门管理</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/dept/saveOrUpdate" method="post" id="editForm">
                    <input type="hidden" name="id">

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-2 control-label">名称：</label>
                        <div class="col-sm-4">
                            <input type="text" name="name" class="form-control" id="name" style="width: 366px"
                                   placeholder="请输入部门名">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-2 control-label">编码：</label>
                        <div class="col-sm-4">
                            <input type="text" name="sn" class="form-control" id="sn" style="width: 366px"
                                   placeholder="请输入部门编码">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary">保存</button>
            </div>
        </div>
    </div>
</div>


</body>
</html>
